package com.ucs.ui;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ucs.domain.Order;

public class OrderListAdaptor extends ArrayAdapter<Order>{
    private List<Order> orders;

    public OrderListAdaptor(Context context, List<Order> orders) {
            super(context, R.layout.order_row, orders);
            this.orders = orders;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	if (convertView == null) {
    		LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    		convertView = li.inflate(R.layout.order_row, null);
    	}
    	TextView ticket_num = (TextView)convertView.findViewById(R.id.ticket_num);
    	TextView table_id = (TextView)convertView.findViewById(R.id.table_id);
    	TextView table_desc = (TextView)convertView.findViewById(R.id.table_desc);

    	Order order = orders.get(position);
//    	Log.d("ucs", "orders.size="+orders.size());
//    	Log.d("ucs", "position="+position);
//       	Log.d("ucs", (order==null)?"null":order.toString());
//    	Log.d("ucs", "orders.getTableID="+order.getTableID());
    	ticket_num.setText(""+order.getTicketNum());
    	table_id.setText(""+TableListAdaptor.getTableName(order.getTableID()));
    	table_desc.setText(""+order.getOrderDetails().size());
    	return convertView;  
    }
}
